//package com.cmict.data.bpm.framework.aspect;
//
//import com.alibaba.fastjson.JSONObject;
//import com.cmict.data.bpm.dal.dataobject.report.ReportUriDO;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.stereotype.Component;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import java.util.UUID;
//
///**
// * @author liutao
// * @date 2022/12/14
// */
//@Aspect
//@Component
//@Slf4j
//public class ReportUriAspect {
//
//    //匹配需要上报的uri
//    @Around("execution(public * com.cmict.data.bpm.framework.flowable.core.listener..*.processCompleted*(..))")
//    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
//        //获取当前请求对象
//        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = attributes.getRequest();
//        ReportUriDO reportUriDTO = new ReportUriDO();
//        Object result = joinPoint.proceed();
//        String uri = request.getRequestURI();
//        String queryString = request.getQueryString();
//        Object[] args = joinPoint.getArgs();
//        String params = "";
//        try {
//            if (args.length > 0) {
//                if (queryString == null) {
//                    Object[] arguments = new Object[args.length];
//                    for (int i = 0; i < args.length; i++) {
//                        if (args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof MultipartFile) {
//                            //ServletRequest不能序列化，从入参里排除，否则报异常：java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
//                            //ServletResponse不能序列化 从入参里排除，否则报异常：java.lang.IllegalStateException: getOutputStream() has already been called for this response
//                            continue;
//                        }
//                        arguments[i] = args[i];
//                    }
//                    if (arguments != null) {
//                        try {
//                            params = JSONObject.toJSONString(arguments);
//                        } catch (Exception e) {
//                            params = arguments.toString();
//                        }
//                    } else if (arguments == null) {
//                        params = queryString;
//                    }
//                } else {
////                    直接以字符串形式获取URL中?后的内容
//                    params = queryString;
////                    JSON格式的URL参数获取
////                    params= JSON.toJSONString(servletRequest.getParameterMap());
//                }
////                params = URLDecoder.decode(params, UTF_8);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error("log error !!", e);
//        }
//        //todo 此处缺少一个判断逻辑，1，拦截到的uri判断是否需要上报，此处可以通过一个枚举类来进行判断
//        // 2.需要解析result,方法为下面的resultParse，返回成功的uri进行上报
//        reportUriDTO.setId(UUID.randomUUID().toString().replace("-", ""));
//        reportUriDTO.setReceivedUri(uri);
//        reportUriDTO.setReceivedUriParams(params);
//        reportUriDTO.setIsReport(0);
//        reportUriDTO.setIsQuery(0);
//        //查询参数
//        reportUriDTO.setQueryParam("");
//        insert(reportUriDTO);
//        return result;
//    }
//}
